package cn.ygh.bbo.generator.config;

import lombok.Data;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author ygh
 * @Type Config.java
 * @Desc
 * @date 2019/10/9
 * @Version V2.0
 */
@Data
public class Config {

    private static final String PROJECT_CONFIG="project.properties";

    private static final String TYPE_CONFIG="type.properties";

    private static Config config=null;

    public static Config getInstance(){
        return config;
    }

    /**
     * 相关类型转换
     */
    private Map<String,String>types=new HashMap<String, String>();

    /**
     * 基础包名
     */
    private String packageName;

    /**
     * 项目报名
     */
    private String projectName;

    /**
     * 数据库地址
     */
    private String url;

    /**
     * 数据库登陆名
     */
    private String username;
    /**
     * 数据库密码
     */
    private String password;

    /**
     * 配置初始化
     */
    public static void init() throws IOException {
        config=new Config();
        Properties conf=new Properties();
        conf.load(Config.class.getClassLoader().getResourceAsStream(PROJECT_CONFIG));
        String packageName=conf.getProperty("packageName");
        String projectName=conf.getProperty("projectName");
        String url=conf.getProperty("url");
        String username=conf.getProperty("username");
        String password=conf.getProperty("password");
        config.setPackageName(packageName);
        config.setProjectName(projectName);
        config.setUrl(url);
        config.setUsername(username);
        config.setPassword(password);
        conf.load(Config.class.getClassLoader().getResourceAsStream(TYPE_CONFIG));
        Map<String,String>types=config.getTypes();
        for (Map.Entry<Object,Object>entry:conf.entrySet()){
            types.put(entry.getKey().toString(),entry.getValue().toString());
        }

    }
}
